Imports System.Xml
Imports Aricie.DNN.Caching

Namespace Aricie.DNN.Caching.Analysis.Graphs
    Public Class DistributedCachingNode

        Private Sub New(ByVal nodeType As TargetNodeType)
            Me._nodeType = nodeType
        End Sub

        Public Sub New()

        End Sub

        Public Sub New(ByVal keyStat As CacheKeyStatistics)
            Me.New(TargetNodeType.KeyStat)
            Me._keyStat = keyStat
        End Sub

        Public Sub New(ByVal groupName As String, ByVal nodes As DistributedCachingGraph)
            Me.New(TargetNodeType.Group)
            Me._keysGroup = New KeysGroup(groupName, nodes)
        End Sub

        Private _nodeType As TargetNodeType
        Private _keysGroup As KeysGroup
        Private _keyStat As CacheKeyStatistics
        Private _grouped As Boolean = False

        Public Property NodeType() As TargetNodeType
            Get
                Return _nodeType
            End Get
            Set(ByVal value As TargetNodeType)
                _nodeType = value
            End Set
        End Property

        Public Property KeysGroup() As KeysGroup
            Get
                Return _keysGroup
            End Get
            Set(ByVal value As KeysGroup)
                _keysGroup = value
            End Set
        End Property

        Public Property KeyStat() As CacheKeyStatistics
            Get
                Return _keyStat
            End Get
            Set(ByVal value As CacheKeyStatistics)
                _keyStat = value
            End Set
        End Property

        Public Property Grouped() As Boolean
            Get
                Return _grouped
            End Get
            Set(ByVal value As Boolean)
                _grouped = value
            End Set
        End Property

        Public Shared Function Identity(ByVal node As DistributedCachingNode) As String
            Return node.ToString
        End Function

        Public Overrides Function ToString() As String
            Select Case Me._nodeType
                Case TargetNodeType.KeyStat
                    Return _keyStat.ToString
                Case Else
                    Return _keysGroup.ToString
            End Select
        End Function

        Public Shared Function AllNodes(ByVal objMatch As DistributedCachingNode) As Boolean
            Return True
        End Function

        Public Shared Function Factory(ByVal reader As XmlReader) As DistributedCachingNode
            Return DirectCast(reader.ReadContentAs(GetType(DistributedCachingNode), Nothing), DistributedCachingNode)
        End Function

    End Class
End Namespace